package org.asiainfo.gateway.config;

import lombok.RequiredArgsConstructor;
import org.asiainfo.gateway.handler.ValidateCodeHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * 路由配置
 *
 * @author dotor-ww
 * {@code @description} 这里目前是验证码接口
 */
@Configuration
@RequiredArgsConstructor
public class RouterFunctionConfiguration {

    private final ValidateCodeHandler validateCodeHandler;

    /**
     * 构建路由树
     *
     * @return routerFunction
     */
    @SuppressWarnings("rawtypes")
    @Bean
    public RouterFunction routerFunction() {
        return RouterFunctions.route()
                //获取验证码状态
                .GET("/getCaptchaStatus", validateCodeHandler::getCaptchaStatus)
                //获取验证码
                .GET("/getCaptcha", validateCodeHandler::createCaptcha)
                //校验验证码
                .POST("/checkCaptcha", validateCodeHandler::checkCaptcha).build();
    }
}
